package cn.tedu.jxc.controller;

import cn.tedu.jxc.mapper.UserMapper;
import cn.tedu.jxc.pojo.dto.ProductDTO;
import cn.tedu.jxc.pojo.dto.UserInsertDTO;
import cn.tedu.jxc.pojo.dto.UserUpdateDTO;
import cn.tedu.jxc.pojo.vo.ProductListItemVO;
import cn.tedu.jxc.pojo.vo.UserStandardVO;
import cn.tedu.jxc.service.ProductService;
import cn.tedu.jxc.service.UserService;
import cn.tedu.jxc.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 用户管理
 */

@Slf4j
@Validated
@RequestMapping("/products")
@RestController
@Api(tags = "09.商品管理")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     * 查询商品列表
     *
     * @return
     */
    @ApiOperation("商品列表")
    @ApiOperationSupport(order = 100)
    @GetMapping("")
    public JsonResult<List<ProductListItemVO>> productList() {
        List<ProductListItemVO> list = productService.list();
        log.debug("将返回商品列表!");
        return JsonResult.ok(list);
    }

    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Valid @RequestBody ProductDTO productDTO){
        productService.addNew(productDTO);
        log.debug("添加成功");
        return JsonResult.ok();
    }
}
